package yxy.cherry.battle.module.affix.buff;

import yxy.cherry.battle.Battle;
import yxy.cherry.battle.Fighter;
import yxy.cherry.battle.module.affix.AffixContext;
import yxy.cherry.battle.module.affix.AffixFactory;
import yxy.cherry.battle.module.affix.Buff;
import yxy.cherry.battle.module.affix.BuffType;
import yxy.cherry.battle.module.record.stream.RecordStream41TriggerBuff;
import yxy.cherry.data.bean.skill;

import java.util.ArrayList;

/**
 * @author James
 * 压制（目标生命值每降低X%，施法者对目标造成的伤害增加X%，伤害增加最高不超过X%）
 * @date 2022/2/25 11:56
 **/
@BuffType(Type = AffixFactory.BuffTypeEnum.压制)
public class Affix71Suppress extends Buff {

    public Affix71Suppress(Fighter source, Fighter target, skill skilldata, int[] params) {
        super(source, target, skilldata, params);
    }

    private int getReduceHPPer() {return getParam(0);}
    private int getAddDamagePer() {return getParam(1);}
    private int getAddDamagePerMax() {return getParam(2);}

    /**
     * 计算增加的伤害比例
     * @param target
     * @return
     */
    private int genAddDamagePer(Fighter target){
        int times = (int) (VALUE_比率分母-target.get血量万分值())/getReduceHPPer();
        int addDamagePerCount = getAddDamagePer() * times;
        if(addDamagePerCount > getAddDamagePerMax()){
            return getAddDamagePerMax();
        }else{
            return addDamagePerCount;
        }
    }

    @Override
    public boolean exec(Fighter source, Fighter target) {
        AffixContext.AffixAction affixAction = getAffixAction();

        AffixContext.AffixTarget affixTarget = affixAction.getTarget(affixAction.get针对目标());
        ArrayList<Long> 伤害流 = affixTarget.get伤害流();
        int addDamagePer = genAddDamagePer(target);
        ArrayList<Long> 结算伤害流 = genFinalDamage(伤害流, affixTarget.getBaseDamageList(), addDamagePer);
        Battle.battleLogger(6,"压制增伤：行动者"+source.getName()+"，原始伤害："+伤害流.toString()+"基础伤害："+affixTarget.getBaseDamageList().toString()+"最终伤害："+结算伤害流.toString());
        affixTarget.set伤害流(结算伤害流);

        getRecord().stream(new RecordStream41TriggerBuff(source,source.getBuffMap().get(getBuffCodeSeq()))).record();
        return true;
    }

    @Override
    public BuffType getBuffType() {
        return BuffType.增益效果;
    }

    @Override
    public BuffStateType getBuffStateType() {
        return BuffStateType.suppressState;
    }
}
